

#pragma once

#include "Message.hpp"
#include <map>
#include <functional>

CYBERTRON_BEGIN

class MessageRouter : public std::enable_shared_from_this<MessageRouter>
{
public:
	CybertronCoreAPI MessageRouter();
	CybertronCoreAPI ~MessageRouter();

	CybertronCoreAPI void clear();
	CybertronCoreAPI void registerHandler(
		std::uint16_t msgId,
		std::function<void(Message&)> handler);
	CybertronCoreAPI void onMessage(Message& msg);

private:
	void zeroMembers();

private:
	MessageRouter(const MessageRouter&);
	MessageRouter& operator = (const MessageRouter&);

private:
	std::map<std::uint16_t, std::function<void(Message&)>> mHandlers;
};

CYBERTRON_END
